<template>
  <div class="search-all">
    <!-- <div class="search-stycon">
      <span>模块样式:</span>
      <div class="search-style">
        <div
          v-for="(item, idx) in searchArr"
          :key="idx"
          :class="[nowId === item.id ? 'active':'', 'search-style-item']"
          :style="item.searchItem"
          @click="activeNowIdx(item.id)"
        ></div>
      </div>
    </div> -->
    <div class="search-con">
      <span>搜索提示:</span>
      <input type="text" v-model="searchText" />
    </div>
    <div class="search-con" style="justify-content: flex-start;">
      <span>背景颜色:</span>&nbsp;&nbsp;&nbsp;
      <el-color-picker
        size="small"
        v-model="background"
        show-alpha
        :predefine="predefineColors">
      </el-color-picker>
    </div>
    <!-- <div class="search-con">
      <span>关键词:</span>
      <input type="text" v-model="mainKey" class="mainKey" />
      <div class="add-tag">
        <span>添加</span>
      </div>
    </div> -->
    <!-- <div class="addcon">
      <div class="search-itemtag">
        <span>
          关键词关键
          <i class="el-icon-close"></i>
        </span>
      </div>
      <div class="search-itemtag">
        <span>
          关键词关键
          <i class="el-icon-close"></i>
        </span>
      </div>
      <div class="search-itemtag">
        <span>
          关键词关键
          <i class="el-icon-close"></i>
        </span>
      </div>
      <div class="search-itemtag">
        <span>
          关键词关键
          <i class="el-icon-close"></i>
        </span>
      </div>
    </div> -->
    <div class="search-con">
      <span>跳转:</span>
      <input type="text" v-model="linkName" class="mainKey" />
      <div class="add-tag" @click="dialogVisible = true">
        <span>选择跳转</span>
      </div>
    </div>
    <pageLink :dialogVisible="dialogVisible" @colse="colsepage" @confirm="confirm"></pageLink>
  </div>
</template>
<script>
import pageLink from "../../../components/linkGroup/pageLink.vue"
import { mapGetters } from "vuex";
export default {
  components: {
    pageLink
  },
  computed: {
    ...mapGetters(["searchObj"]),
    searchText: {
      get() {
        return this.searchObj.searchText
      },
      set(val) {
        this.searchObj.searchText = val;
        this.$store.commit("search/SET_searchObj", this.searchObj);
      }
    },
    background: {
      get() {
        console.log(this.searchObj)
        return this.searchObj.background
      },
      set(val) {
        this.searchObj.background = val;
        this.$store.commit("search/SET_searchObj", this.searchObj);
      }
    },
    linkName: {
      get() {
        return this.searchObj.linkName;
      },
      set(val) {
        console.log(val)
        this.searchObj.linkName = val;
        this.$store.commit("search/SET_searchObj", this.searchObj);
      }
    }
  },
  props: ['nowComIdx'],
  watch: {
    searchObj: {
      handler(oldval, newval) {
        console.log(oldval, newval);
        // 更新vuex里面的PageJSON
        this.$store.dispatch("apply/PageJSONUpData");
        // 更新父组件中的PageJSON
        this.$emit("updataNowPageJSON");
      },
      deep: true
    }
  },
  data() {
    return {
      dialogVisible: false,
      nowId: 0,
      placeholder: "",
      mainKey: "",
      goUrl: "",
      PageAll: [],
      searchArr: [
        {
          id: 1,
          searchItem: {
            borderRadius: "14px",
            border: "1px solid rgba(224,225,232,1)"
          }
        },
        {
          id: 2,
          searchItem: {
            borderRadius: "1px",
            border: "1px solid rgba(224,225,232,1)"
          }
        },
        {
          id: 3,
          searchItem: {
            background: "rgba(0,0,0,.05)",
            borderRadius: "14px"
          }
        },
        {
          id: 4,
          searchItem: {
            background: "rgba(0,0,0,0.05)",
            borderRadius: "3px"
          }
        }
      ],
      color: 'rgba(255, 69, 0, 0.68)',
      predefineColors: [
        '#ff4500',
        '#ff8c00',
        '#ffd700',
        '#90ee90',
        '#00ced1',
        '#1e90ff',
        '#c71585',
        'rgba(255, 69, 0, 0.68)',
        'rgb(255, 120, 0)',
        'hsv(51, 100, 98)',
        'hsva(120, 40, 94, 0.5)',
        'hsl(181, 100%, 37%)',
        'hsla(209, 100%, 56%, 0.73)',
        '#c7158577'
      ]
    };
  },
  methods: {
    // 确定选中链接
    confirm(val) {
      this.linkName = val.title;
      this.searchObj.link = val.link;
      console.log(val)
    },
    colsepage() {
      this.dialogVisible = false;
    },
    // 设置选中样式
    activeNowIdx(id) {
      this.nowId = id;
      this.$store.commit('search/SET_STYLE', id);
      this.$store.dispatch('apply/PageJSONUpData');
    },
    update() {
      this.$store.commit("activity/SET_OBJ", this.activity);
      // 更新vuex里面的PageJSON
      this.$store.dispatch("apply/PageJSONUpData");
      // 更新父组件中的PageJSON
      this.$emit("updataNowPageJSON");
    }
  }
};
</script>
<style lang="scss" scoped>
@import "./diyset.scss";
.search-all {
  width: 100%;
  height: 100%;
  padding-top: 20px;
  display: flex;
  flex-direction: column;
  .search-style {
    width: 220px;
    height: auto;
    margin-top: -10px;
    .search-style-item {
      width: 100%;
      height: 28px;
      margin-top: 10px;
      background: rgba(255, 255, 255, 1);
      border-radius: 14px;
      border: 1px solid rgba(224, 225, 232, 1);
    }
    .search-style-item.active {
      border-radius: 1px;
      border:1px solid rgba(0,138,255,1) !important;
    }
  }
  .search-stycon {
    @include flexCon(290px, auto, flex-start, space-between, 40px);
    position: relative;
    align-items: flex-start;
  }
  .search-con {
    @include flexCon(290px, 50px, center, space-between, 40px);
    position: relative;
    margin-top: 20px;
    input {
      @include wd(220px, 30px);
      background: rgba(255, 255, 255, 1);
      border-radius: 3px;
      font-size: 14px;
      padding-left: 8px;
      border: 1px solid rgba(223, 223, 223, 1);
    }
    .mainKey {
      width: 170px;
      height: 30px;
      border-radius: 2px;
      margin-left: 10px;
      border: 1px solid rgba(224, 225, 232, 1);
    }
    .add-tag {
      @include wd(auto, 30px);
      border-radius: 2px;
      font-size: 14px;
      text-align: center;
      line-height: 30px;
      padding: 0 10px;
      border: 1px solid rgba(224, 225, 232, 1);
      cursor: pointer;
    }
  }
  .addcon {
    @include flexCon(320px, 50px, center, space-between, 32px);
    position: relative;
    justify-content: flex-start;
    flex-wrap: wrap;
    margin-top: 20px;
    input {
      @include wd(225px, 30px);
      background: rgba(255, 255, 255, 1);
      border-radius: 3px;
      font-size: 14px;
      padding-left: 8px;
      border: 1px solid rgba(223, 223, 223, 1);
    }
    .search-itemtag {
      width: auto;
      height: 20px;
      padding: 2px 4px;
      background: rgba(243, 244, 246, 1);
      border-radius: 2px;
      margin-left: 6px;
    }
  }
}
</style>
